from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

driver = webdriver.Edge()
driver.get('http://10.59.9.12:7001/')
driver.maximize_window()
sleep(2)
# 切换窗口
# driver.switch_to.window(driver.window_handles[-1])
# ⑧　获取所有窗口句柄
window = driver.current_window_handle
# ⑨　打印获取所有窗口句柄
print(window)
# 点击登录
driver.find_element(By.LINK_TEXT,'登录').click()
sleep(1)
# 输入账号密码
driver.find_element(By.NAME,'username').send_keys("18238680385")
driver.find_element(By.NAME,'password').send_keys('123456')
# 强等手动输入验证码
sleep(6)
# 点击登录按钮
driver.find_element(By.XPATH,'//*[@id="theForm"]/div[5]/a').click()
sleep(5)
# 点击首页
driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/ul/li[1]/a').click()
sleep(1)
# 搜索框输入内容
driver.find_element(By.TAG_NAME,'input').send_keys('非洲之心')
sleep(1)
# 点击搜索按钮
driver.find_element(By.XPATH,'//*[@id="searchForm"]/div[2]/input').click()
sleep(1)
# 点击商品进入商品详情
driver.find_element(By.XPATH,'/html/body/div[5]/div[2]/div[2]/div[1]/ul/li/div[1]/span/a/img').click()
sleep(1)
# 点击加入购物车
driver.find_element(By.CSS_SELECTOR,'#add-cart').click()
sleep(5)
# 点击立即购买 进入确认订单页面
driver.find_element(By.ID,'buy-cart').click()
sleep(1)
# 点击下一步
driver.find_element(By.CLASS_NAME,'ask-btn').click()
sleep(1)
# 支付成功
finish = driver.find_element(By.XPATH,'/html/body/div[4]/div[3]/span').text
print(finish)

sleep(5)
driver.quit()